package com.sc.server.member.config;

/**
 * @author yuantongqin
 * desc: 登录的上下文
 * 2020-08-11
 */


public class LoginContext {

    private static ThreadLocal<LoginContext> userinfo = new ThreadLocal<>();

    private Long userId;

    public LoginContext() {
    }

    public LoginContext(Long userId) {
        this.userId = userId;
    }

    public static class Builder{

        private static Long userId;

        public Builder setUserId(Long userId){
            this.userId = userId;
            return this;
        }

        public LoginContext build(){
            LoginContext loginContext = new LoginContext(this.userId);
            userinfo.set(loginContext);
            return loginContext;
        }


    }

    public static Builder builder(){
        return new Builder();
    }

    public static Long getUserId(){
     return userinfo.get().userId;
    }

    public static void remove(){
        userinfo.remove();
    }
}
